package projectisd.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
/** 
 * Dit is de klas die de functies uit Klas Async maakt en functies aanmaakt
 * om de array list te updaten, verwijderen en iets aan toe te voegen daaraan.
 * @author Team 2
 * @version 7.0
 */
public class KlasDelegate {
    private ProjectServiceAsync projectService = GWT.create(ProjectService.class);
    KlasGUI gui;
    
    void listKlassen() {
    	projectService.listKlassen(new AsyncCallback<List<Klas>> () {
                    public void onFailure(Throwable caught) {
                        gui.service_eventListKlasFailed(caught);
                    }
        
                    public void onSuccess(List<Klas> result) {
                        gui.service_eventListRetrievedFromService(result);
                        
                    }
        }//end of inner class
        );//end of listKlassens method call.
    }
    
    void addKlas(final Klas klas) {
        projectService.addKlas(klas, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventAddKlasFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventAddKlasSuccessful();
            }
        }//end of inner class
        );//end of addKlas method call.        
    }

    void updateKlas(final Klas klas) {
    	projectService.updateKlas(klas, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventUpdateKlasFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventUpdateSuccessful();
            }
        }//end of inner class
        );//end of updateKlas method call.        
    }

    void removeKlas(final Klas klas) {
    	projectService.removeKlas(klas, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventRemoveKlasFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventRemoveKlasSuccessful();
            }
        }//end of inner class
        );//end of updateKlas method call.        
    }
    
}
